package com.example.demo.config;


import io.shardingsphere.core.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.core.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

import java.text.SimpleDateFormat;
import java.util.Collection;

/**
 * 精确分片算法类
 * @author 510830970@qq.com
 */
public class SharedingTablePreciseAlgorithm implements PreciseShardingAlgorithm<String> {
    public SharedingTablePreciseAlgorithm() {
    }

    private String DateToTable(String tablePre, PreciseShardingValue preciseShardingValue){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return tablePre+ sdf.format(preciseShardingValue.getValue());
    }

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
        return DateToTable("t_order_",preciseShardingValue);
    }
}
